import React, { useState ,useRef} from 'react';
import { Modal, Button ,Input,Form} from 'antd';
import http from '../../../../services/http'
const { TextArea } = Input;

export default function Look(props) {
    let form=useRef()
    const [visible, setVisible] = useState(false);
    const [data,setData] = useState({})
    const [id,setId] = useState('')

    const edit= (a)=>{
        setId(a.fn)
        http({
            url:'/getlookreportpcuser',
            data:{
                user_id:a.fn
            }
          }).then( (res) => {
            setData(res[0]) 
            form.current.setFieldsValue({
                user_name:res[0].user_name,
                DBP:res[0].DBP,
                SBP:res[0].SBP,
                BP:res[0].BP,
                health:res[0].health,
                hemameba:res[0].hemameba,
                red_blood:res[0].red_blood,
                hemoglobin:res[0].hemoglobin,
                HCT:res[0].HCT,
                opinionFirst:res[0].opinionFirst,
                ALT:res[0].ALT,
                AST:res[0].AST,
                GGT:res[0].GGT,
                opinionSecond:res[0].opinionSecond,
                pulse:res[0].pulse,
                indexa:res[0].indexa,
                conclusion:res[0].conclusion,
                order_orderId:res[0].order_orderId
            })
          })
          setVisible(true)
    }

    const onFinish = (values) => {
        http({
            url:'/editlookreportpcuser',
            data:{
                user_id:id,
                user_name:values.user_name,
                DBP:parseFloat(values.DBP),
                SBP:parseFloat(values.SBP),
                BP:parseFloat(values.BP),
                health:parseFloat(values.health),
                hemameba:parseFloat(values.hemameba),
                red_blood:parseFloat(values.red_blood),
                hemoglobin:parseFloat(values.hemoglobin),
                HCT:parseFloat(values.HCT),
                opinionFirst:values.opinionFirst,
                ALT:parseFloat(values.ALT),
                AST:parseFloat(values.AST),
                GGT:parseFloat(values.GGT),
                opinionSecond:values.opinionSecond,
                pulse:parseFloat(values.pulse),
                indexa:parseFloat(values.indexa),
                conclusion:values.conclusion,
                order_orderId:values.order_orderId
            }
          }).then( (res) => {
            window.location.reload()
        })
    };
    
    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };

    return (
        <span>
            <a  type="primary" onClick={
                edit.bind(this,props)}
                >
                编辑
            </a>
            <Modal
                className='data' 
                title="编辑"
                centered
                footer={
                    [] // 设置footer为空，去掉 取消 确定默认按钮
                }
                onCancel={() => setVisible(false)}
                visible={visible}>
                    <Form  
                    ref={form}
                    name="basic"
                    labelCol={{ span: 8 }}
                    wrapperCol={{ span: 15 }}
                    initialValues={{ remember: true }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    >
                         <Form.Item
                            label="姓名"
                            name="user_name"
                            shouldUpdate
                            rules={[{
                                message: '请输入姓名' }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="舒张压"
                            name="DBP"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="收缩压"
                            name="SBP"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="血小板"
                            name="BP"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="医疗保健"
                            name="health"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="白细胞"
                            name="hemameba"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="红细胞"
                            name="red_blood"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="血红蛋白"
                            name="hemoglobin"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="红细胞积压"
                            name="HCT"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="初步意见(血常规)"
                            name="opinionFirst"
                            rules={[{ message: '初步意见' }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="丙氨酸基转氨酶"
                            name="ALT"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="AST/ALT"
                            name="AST"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="r-谷氨酰转氨酶"
                            name="GGT"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="初步意见(肝功能)"
                            name="opinionSecond"
                            rules={[{ message: '初步意见' }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="脉搏"
                            name="pulse"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input/>
                        </Form.Item>
                        <Form.Item
                            label="指数"
                            name="indexa"
                            rules={[{
                                message: '请输入数字' ,
                                pattern: new RegExp(/^[1-9]\d*$/, "g")
                            }]}
                            >
                            <Input />
                        </Form.Item>
                        <Form.Item
                            label="结论"
                            name="conclusion"
                            rules={[{message: '初步结论' }]}
                            >
                            <Input placeholder={data.conclusion}/>
                        </Form.Item>
                        <Form.Item
                            label="订单号"
                            name="order_orderId"
                            rules={[{ message: '初步结论' }]}
                            >
                            <Input />
                        </Form.Item>
                        <Form.Item wrapperCol={{ offset: 11, span: 16 }}>
                            <Button onClick={() => setVisible(false)}>
                            取消
                            </Button>

                            <Button type="primary" htmlType="submit" style={{margin:'10px'}} onClick={() => setVisible(false)}>
                            提交
                            </Button>
                        </Form.Item>
                    </Form>
            </Modal>
        </span>
    )
}